{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ART decision tree classifier attack"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook shows how to compute adversarial examples on decision trees (as described in by Papernot et al. in https://arxiv.org/abs/1605.07277). Due to the structure of the decision tree, an adversarial example can be computed without any explicit gradients, only by traversing the learned tree structure.\n",
    "\n",
    "Consider the following simple decision tree for four dimensional data, where we go to the left if a condition is true:\n",
    "\n",
    "                    F1<3\n",
    "           \n",
    "              F2<5        F2>2\n",
    "                \n",
    "         F4>3     C1    F3<1     C3* \n",
    "             \n",
    "      C1     C2       C3    C1  \n",
    "      \n",
    "Given sample [4,4,1,1], the tree outputs C3 (as indicated by the star). To misclassify the sample, we walk one node up and explore the subtree on the left. We find the leaf outputting C1 and change the two features, obtaining [4,1.9,0.9,1]. In this implementation, we change only the features with wrong values, and specify the offset in advance."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Applying the attack"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.tree import DecisionTreeClassifier\n",
    "from sklearn.datasets import load_digits\n",
    "from matplotlib import pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "from art.attacks.evasion import DecisionTreeAttack\n",
    "from art.estimators.classification import SklearnClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9 0 1 2 3]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.colorbar.Colorbar at 0x7fa24585ca10>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASQAAAD4CAYAAABFcpsMAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/A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mIrk34LFtEHCrs4mbZkpAi+iwtpIgog/HMzLiD+DVJSBF9le1HIqIohU3759SRiJ4y4FnXuoaRtEHSA5IelHTFqDElIUX0lasN2upci6h2AfkEg6c5TgEukHTKKCGlyxbRYw0Nap8KPGj7IQBJnwHOA+5fakFyC9N+kh4HlrpFyVpgb+PBlOFQ/W75XuPzW7ZfupwCJN3M4LvWsQp4Zt79tO3pqpx3ARtsv6+6vwh4o+33LzWmVlpIo/yHkrTF9lQb8Yzbofrd8r0mm+0NDRW10CGRI7V0MoYUEcu1Czhh3v064NFRCkpCiojluht4laSTqn3Tzge+MEpBJQ1qT487gBYdqt8t3yuwfUDS+4FbgBXAJ23fN0pZrQxqR0SMIl22iChGElJEFKOIhNTUsvOSSDpB0tcl7ZB0n6RLxh1TkyStkPQtSV8cdyxNknS0pM2SdlZ/d6eNO6Y+GfsYUrXs/LsMtsjdxWDE/gLbS17lWRJJxwHH2d4m6ShgK/DOSf9ecyR9EJgC1tg+Z9zxNEXS9cB/276mmjFabfun446rL0poIf1q2bntfcDcsvOJZnu37W3Vz08BO4DjxxtVMyStA94BXDPuWJokaQ3wJuBaANv7koy6VUJCOh54eN79Lg6Rf7hzJJ0IrAfuGm8kjbkKuBwoa++K5XsF8Djwqao7eo2kI8cdVJ+UkJAaW3ZeIkkvBD4PXGr7yXHHs1ySzgH22N467lhacBjweuBq2+uBp4FDYkxzUpSQkBpbdl4aSSsZJKNNtm8cdzwNOR04V9IPGHSvz5B0w3hDaswuYJftuZbsZgYJKjpSQkJqbNl5SSSJwVjEDtsfG3c8TbF9pe11tk9k8Hf1NdsXjjmsRth+DHhY0snVS2cywhYaMbqxPzrS5LLzwpwOXATcK2l79drf2/7SGGOK4T4AbKr+5/gQcPGY4+mVsU/7R0TMKaHLFhEBJCFFREGSkCKiGElIEVGMJKSIKEYSUkQUIwkpIorxfxL4fOXne+jCAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "digits = load_digits()\n",
    "X = digits.data\n",
    "y = digits.target\n",
    "\n",
    "clf = DecisionTreeClassifier()\n",
    "clf.fit(X,y)\n",
    "clf_art = SklearnClassifier(clf)\n",
    "print(clf.predict(X[:14]))\n",
    "plt.imshow(X[0].reshape(8,8))\n",
    "plt.colorbar()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We now craft adversarial examples and plot their classification. The difference is really small, and often only one or two features are changed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Decision tree attack: 100%|██████████| 14/14 [00:00<00:00, 1546.08it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6 4 4 6 6 4 1 2 4 4 6 4 6 4]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7fa24570fa10>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPUAAAD4CAYAAAA0L6C7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAALLElEQVR4nO3df6jV9R3H8derq+U0zS1bhVdmjZK1jWVdHOIIptvQJRVssCtUrA0uDIoiWdRobPs/wv0xArFakEuaFURrtVhFBc78kXPZtWHS8Gal0fplpN587497BGu33e855/vj3PeeD7h4fxzu533Qp99zv/ec78cRIQB5nNT0AADKRdRAMkQNJEPUQDJEDSQzpYpverJPiWmaUcW3btTonHrv01lnvV3bWq8dml3bWtNGjta2Vh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BHbmp6lAlMkXSTpjohYKOmQpEl3jqcXoh6RNO+Ej/sl7W9ollLZnqqxoNdHRJbLKy+RdJntVzX2o9JS2/c2O1JpRiSNRMTxR1QbNRb5pNILUW+RdJ7tc1onJgYlPdzwTF2zbY39bDYcEbc3PU9ZIuKWiOiPiPka+7t6MiKubHisUkTEG5L22V7Q+tQySZPuxGa7G+SVLiJGbV8r6XFJfZLuiohdDY9VhiWSrpL0D9s7Wp/7RUQ82uBMmNh1kta3DjB7JV3T8Dxta/xXWgDK1QsPvwGUiKiBZIgaSIaogWSIGkiGqIFkiBpI5j/kuKMFZCbV2gAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "attack = DecisionTreeAttack(clf_art)\n",
    "adv = attack.generate(X[:14])\n",
    "print(clf.predict(adv))\n",
    "plt.imshow(adv[0].reshape(8,8))\n",
    "# plt.imshow((X[0]-adv[0]).reshape(8,8))  ##use this to plot the difference"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The change is possibly larger if we specify which class the sample should be (mis-)classified as. To do this, we just specify a label for each attack point."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Decision tree attack: 100%|██████████| 14/14 [00:00<00:00, 1073.48it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6 6 7 7 8 8 9 9 1 1 2 2 3 3]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7fa245684f50>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPUAAAD4CAYAAAA0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TA2gHL10pAZQAqIGkumJqG0vt/2y7T22b256njLYnmf7KdvDtnfZvr7pmcpku8/2C7YfaXqWMtmebXuj7d2tv7vFTc/UrsZ/pm5tEPBPjV0uaUTSFkmrIuKlRgfrku2zJZ0dEdttz5S0TdIVk/1+HWf7RkkDkmZFxMqm5ymL7XskPRsR61pX0J0eEe80PVc7euFIvUjSnojYGxFHJG2QdHnDM3UtIl6PiO2t99+XNCxpbrNTlcN2v6RLJa1repYy2Z4l6RJJd0pSRByZbEFLvRH1XEn7Tvh4REn+8R9ne76khZI2NztJadZIuknSsaYHKdm5kg5Kurv1o8U62zOaHqpdvRC1x/lcmt+z2T5V0gOSboiI95qep1u2V0o6EBHbmp6lAlMkXSTpjohYKOmQpEl3jqcXoh6RNO+Ej/sl7W9ollLZnqqxoNdHRJbLKy+RdJntVzX2o9JS2/c2O1JpRiSNRMTxR1QbNRb5pNILUW+RdJ7tc1onJgYlPdzwTF2zbY39bDYcEbc3PU9ZIuKWiOiPiPka+7t6MiKubHisUkTEG5L22V7Q+tQySZPuxGa7G+SVLiJGbV8r6XFJfZLuiohdDY9VhiWSrpL0D9s7Wp/7RUQ82uBMmNh1kta3DjB7JV3T8Dxta/xXWgDK1QsPvwGUiKiBZIgaSIaogWSIGkiGqIFkiBpI5j/kuKMFZCbV2gAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "adv = attack.generate(X[:14],np.array([6,6,7,7,8,8,9,9,1,1,2,2,3,3]))\n",
    "print(clf.predict(adv))\n",
    "plt.imshow(adv[0].reshape(8,8))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally, the attack has an offset parameter which specifies how close the new value of the feature is compared to the learned threshold of the tree. The default value is very small (0.001), however the value can be set larger when desired. Setting it to a very large value might however yield adversarial examples outside the range or normal features!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Decision tree attack: 100%|██████████| 14/14 [00:00<00:00, 1586.65it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6 4 4 4 6 4 1 2 4 4 6 4 4 4]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.colorbar.Colorbar at 0x7fa24562fd90>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASwAAAD8CAYAAADNNJnuAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAASzUlEQVR4nO3dfaxlVX3G8e/D5a28BXRURgbL0CARjQ72iqWkBAUV0YiY0kCjtdpkbCJGUxOD9Q81xqRp4ktjLDoighEhCE4hiCCoFE2rMuiIMw7UEalcBh0HNDMiMMy9T/84Z+pluC/73rP3Pmed/XySlXvO3ufu9Tte5udaa6+9lmwTEVGC/YYdQEREVUlYEVGMJKyIKEYSVkQUIwkrIoqRhBURxUjCioiBSbpM0nZJm2Yd+5CkByVt7JdzBq0nCSsi6nA5cPYcxz9he02/3DRoJUlYETEw23cAjzRdz/5NXHTi8EO9/4qjmrj0UB184JOt1ve8gxr/+/+/380c0lpd2/9wWGt1YbVXV4v27Pgt07seHejLveYVh/rhR6Yrffauu5/YDDw+69A62+sq/OpFkv4O2AC81/Zvlx7pHzWSsPZfcRRHf/BdTVx6qF6welur9X3q+Gtaq+v6XS9ura5/v/v01uqafryR/8SH7lcf/tTA13j4kWl+cMvzKn12YuXPHrc9ucQqLgE+Arj/82PA25d4jacYz79mRCzK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OkI4HTg8wC2dydZjZZRSFjHAA/Mej/FmPzD3kvSccDJwPeHG0ltPgm8DyjrydnFHQ/8BvhCv7t7qaRssjlCRiFhaY5jYzPXQtJhwHXAe2zvHHY8g5L0emC77buGHUsD9gdeClxi+2TgUWAsxlTHxSgkrCng2FnvVwHbhhRLrSQdQC9ZXWn7q8OOpyanAW+QdD+97vsrJX1puCHVZgqYsr23JXwtvQQWI2IUEtadwAmSVvcHOS8AbhhyTAOTJHpjIVtsf3zY8dTF9vttr7J9HL2/1bdsv3nIYdXC9q+ABySd2D90JjAWN0nGxdDXw7K9R9JFwC3ABHCZ7c1DDqsOpwFvAX4iaWP/2D/bvmmIMcXi3gVc2f8/z/uAtw05nphl6NMaIiKqGoUuYUREJUlYEVGMJKyIKEYSVkQUIwkrIoqRhBURxUjCiohi/B/svB2UohAkCQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "attack = DecisionTreeAttack(clf_art,offset=20.0)\n",
    "adv = attack.generate(X[:14])\n",
    "print(clf.predict(adv))\n",
    "plt.imshow(adv[0].reshape(8,8))\n",
    "plt.colorbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
